package org.sdfc.model.dfc

import com.documentum.fc.client.IDfSession
import com.documentum.fc.common.IDfId
import com.documentum.fc.common.IDfTime

import org.sdfc.model.TypedObject
import org.sdfc.model.attr._

/** TypedObject implementation backed by the DFC.
 */
trait DfcTypedObject extends TypedObject {
  
  /** Iterates over the values of a RepeatingBooleanAttribute. */
  def getValues(attr : RepeatingBooleanAttribute) : Iterator[Boolean] = new Iterator[Boolean] {
    private val maxIndex = getValueCount(attr) - 1
    private var index = -1
    
    def hasNext = index < maxIndex
    def next() = { index += 1; getRepeatingBoolean(attr, index) }
  }
  
  /** Iterates over the values of a RepeatingIntAttribute. */
  def getValues(attr : RepeatingIntAttribute) : Iterator[Int] = new Iterator[Int] {
    private val maxIndex = getValueCount(attr) - 1
    private var index = -1
    
    def hasNext = index < maxIndex
    def next() = { index += 1; getRepeatingInt(attr, index) }
  }
  
  /** Iterates over the values of a RepeatingStringAttribute. */
  def getValues(attr : RepeatingStringAttribute) : Iterator[String] = new Iterator[String] {
    private val maxIndex = getValueCount(attr) - 1
    private var index = -1
    
    def hasNext = index < maxIndex
    def next() = { index += 1; getRepeatingString(attr, index) }
  }
  
  /** Iterates over the values of a RepeatingIdAttribute. */
  def getValues(attr : RepeatingIdAttribute) : Iterator[IDfId] = new Iterator[IDfId] {
    private val maxIndex = getValueCount(attr) - 1
    private var index = -1
    
    def hasNext = index < maxIndex
    def next() = { index += 1; getRepeatingId(attr, index) }
  }
  
  /** Iterates over the values of a RepeatingTimeAttribute. */
  def getValues(attr : RepeatingTimeAttribute) : Iterator[IDfTime] = new Iterator[IDfTime] {
    private val maxIndex = getValueCount(attr) - 1
    private var index = -1
    
    def hasNext = index < maxIndex
    def next() = { index += 1; getRepeatingTime(attr, index) }
  }
  
  /** Iterates over the values of a RepeatingDoubleAttribute. */
  def getValues(attr : RepeatingDoubleAttribute) : Iterator[Double] = new Iterator[Double] {
    private val maxIndex = getValueCount(attr) - 1
    private var index = -1
    
    def hasNext = index < maxIndex
    def next() = { index += 1; getRepeatingDouble(attr, index) }
  }
  
}
